
    class Creatmes {
        constructor() {
            this.username = document.querySelector('#recipient-username')
            this.pwd = document.querySelector('#recipient-password')
            this.phone = document.querySelector('#recipient-phone')
            this.checkpwd = document.querySelector('#recipient-checkpassword')
            this.btn = document.querySelector('.btn')
            this.span1 = document.querySelector('.tips1')
            this.span2 = document.querySelector('.tips2')
            this.showU=false
            this.showPh=false
            this.getmes()
            this.checkU()
            this.checkphone()
            this.load()
        }
        getmes() {
            return JSON.parse(localStorage.getItem('abc')) || []
        }
        load() {
            this.btn.onclick = () => {
                if (!this.username.value || !this.pwd.value || !this.checkpwd.value || !this.phone.value) {
                    alert('请输入完整信息')
                    return
                }
                if (this.pwd.value != this.checkpwd.value) {
                    alert('两次密码不一致，请重新输入')
                    return
                }
                var obj = {
                    username: this.username.value,
                    pwd: this.pwd.value,
                    checkpwd: this.checkpwd.value,
                    phone: this.phone.value
                }
                // let arr = this.getmes()
                // arr.push(obj)
                // localStorage.setItem('abc', JSON.stringify(arr))
                if (this.showU == false && this.showPh == false) {
                    // console.log(showP)
                    // console.log(showU)
                    let arr = this.getmes()
                    arr.push(obj)
                    localStorage.setItem('abc', JSON.stringify(arr))
                    this.username.value=''
                    this.phone.value=''
                    this.pwd.value=''
                    this.checkpwd.value=''
                    alert('注册成功，正在前往登录界面...')
                    setTimeout(()=>{
                        location.href='login.html'
                    },1500)
                }else{
                    console.log(this.showPh)
                    console.log(this.showU)
                    alert('注册失败，请修改注册信息')
                    return
                }
            }
        }
        checkU() {
            this.username.onblur = () => {
                let arr = this.getmes()
                if (arr.length > 0) {
                    var res = arr.some((x) => {
                        return x.username == this.username.value
                    })
                    var showU = res
                    if (res) {
                        this.span1.innerHTML = '该用户名已经被注册'
                    } else {
                        this.span1.innerHTML = ''
                    }
                }
            }
        }
        checkphone() {
            this.phone.onblur = () => {
                let arr = this.getmes()
                if (arr.length > 0) {
                    var res = arr.some((x) => {
                        return x.phone == this.phone.value
                    })
                    var showPh = res
                    if (res) {
                        this.span2.innerHTML = '该号码已经被使用'
                    } else {
                        this.span2.innerHTML = ''
                    }
                }
            }
        }
    }
    new Creatmes()
